package com.apes.enquiry.brand.repository;

import com.apes.enquiry.brand.model.SpBrand;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * 类描述：
 *
 * @ClassName QualityRepository
 * @Description 描述
 * @Author wushilong
 * @Date 2022/11/3 15:32
 * @Version 1.0
 */
public interface SpBrandRepository extends CustomRepository<SpBrand, String> {

    @Query(value = "select a from SpBrand a where a.name = :name")
    SpBrand findByName(String name);

    @Query(value = "select a.name from SpBrand a")
    List<String> findAllName();

    @Query(value = "select a.name as name from SpBrand a")
    List<Map<String, String>> findAllBrand();

    @Query(value = "SELECT A.PPMC name, A.PZMC qualityName FROM SP_MAS_PPXX A, (SELECT MAX(ID) AS ID FROM SP_MAS_PPXX GROUP BY PPMC) B\n" +
            "WHERE A.ID = B.ID AND A.PZMC IS NOT NULL", nativeQuery = true)
    List<Map<String, String>> findAllQuality();

    @Query(value = "select * from sp_mas_ppxx a where REGEXP_LIKE(id, :param, 'i') or REGEXP_LIKE(PPMC, :param, 'i') and a.YXBJ = 1",nativeQuery = true)
    Page<SpBrand> findAllLikeIdAndName(String param, Pageable var2);

    @Query(value = "select a from SpBrand a where a.qualityId = '003' and a.valid = true ")
    Page<SpBrand> findAllBrandStandard(Pageable var2);

    @Query(value = "select a from SpBrand a where a.qualityId not in ('000001','000003','000004','003') AND valid = true")
    List<SpBrand> findAllNotBrandStandard();

    @Query(value = "select a from SpBrand a where a.id in :id and a.valid = true")
    List<SpBrand> findInId(List<String> id);
}
